<!DOCTYPE HTML>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="referrer" content="never">
    <title th:text="${source.title}"></title>
    <script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
    <link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body style="background-color: #F1F1F1">

<!-- 导航栏 -->
<div th:insert="~{header :: nav}"></div>

<!-- 文章 -->
<div class="container" style="margin-top: 50px;" id="content">
    <div class="row">
        <div class="col-md-8" id="articleContent" style="border: 2px solid #5CB85C; margin-top: 20px; border-radius: 3px">
            <h2 th:text="${source.title}" class="text-success"></h2>
            <div style="border: 3px solid #5CB85C"></div>
        </div>
        <div class="col-md-4">
            <div class="panel panel-danger" style="margin-top: 20px">
                <div class="panel-heading">
                    <h3 class="panel-title">来源 / 解析</h3>
                </div>
                <div class="panel-body">
                    <a class="btn btn-danger" th:href="${source.value}" target="_blank"><span class="glyphicon glyphicon-film"></span> [[${source.provider}]]</a>
                    <a class="btn btn-success" th:href="${source.parser}" target="_blank"><span class="glyphicon glyphicon-fire"></span> [[${source.parserName}]]</a>
                </div>
            </div>
            <div class="panel panel-danger videoList" style="margin-top: 20px">
                <div class="panel-heading">
                    <h3 class="panel-title">相关信息</h3>
                </div>
                <div class="panel-body">
                    <h4><span class="label label-default">作者</span> <span class="label label-success" th:text="${source.author}"></span></h4>
                    <h4><span class="label label-default">时间</span> <span class="label label-success" th:text="${source.time}"></span></h4>
                    <button id="collectBtn" class="btn btn-danger btn-block" data-toggle="modal" data-target="#collectModal" th:if="${#httpServletRequest.remoteUser}"><span class="glyphicon glyphicon-heart" ></span> 收藏</button>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- End 播放器 -->

<!-- 私藏 模态框 -->
<div class="modal fade" id="collectModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title">
                    私藏
                </h4>
            </div>
            <div class="modal-body" style="text-align: center" id="createBody">
                <form class="form-horizontal">
                    <div class="form-group">
                        <label class="col-sm-2 control-label">标题</label>
                        <div class="col-sm-10">
                            <p class="form-control" id="collectName" ></p>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">分类</label>
                        <div class="col-sm-10" id="selectDiv">
                            <select id="categorySelect" name="categorySelect" class="form-control">

                            </select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
                <button type="button" class="btn btn-info" id="createCategoryItem">
                    确定
                </button>
            </div>
        </div>
    </div>
</div>
<!-- End 私藏 模态框 -->

<!-- 提示 模态框 -->
<div class="modal fade" id="promptModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
                    &times;
                </button>
                <h4 class="modal-title">
                    提示
                </h4>
            </div>
            <div class="modal-body" style="text-align: center">
                <p style="color:red; font-size: 20px" id="result"></p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭
                </button>
            </div>
        </div>
    </div>
</div>
<!-- End 提示 模态框 -->

<script th:inline="javascript">
    var articleContent = [[${source.Content}]];
    $("#articleContent").append(articleContent);
</script>

<script style="text/javascript">

    /* 私藏 */
    $("#collectBtn").click(function () {
         $.get("/user/categories", function (data) {
             $("#collectName").text(articleTitle);
             $("#categorySelect").remove();
             if (data.length == 0){

             }else {
                 var select = $("<select id=\"categorySelect\" name=\"categorySelect\" class=\"form-control\"></select>");
                 $("#selectDiv").append(select);
                 for (var i = 0; i < data.length; i++){
                     var option = $("<option></option>")
                     option.val(data[i].id);
                     option.text(data[i].name);
                     $("#categorySelect").append(option);
                 }
             }
         })
    });

    /* 私藏到指定分类 */
    $("#createCategoryItem").click(function(){
        $.post("/user/category/item/add",{
            "type": "ARTICLE",
            "name": articleTitle,
            "value": "/view?u="+articleValue,
            "id": $("#categorySelect").val()
        },function(data){
            $('#collectModal').modal('hide');
            $("#result").text(data.message);
            $('#promptModal').modal('show');
        });
    });

</script>
</body>
</html>
